#ifndef CNSVARIANTKEY_H
#define CNSVARIANTKEY_H

#include <QVariant>
#include "cnsEnum.h"

class CnsVariantKey {

public:
    explicit CnsVariantKey()
    {}
    ~CnsVariantKey() = default;

    CnsVariantKey(const QVariant &v)
    {
        m_value = std::move(v);
    }

    CnsVariantKey(const QString &s)
    {
        m_value = s;
        m_type = "QString";
    }

    bool isValid()
    {
        return m_value.isValid();
    }

    inline const QString &type() const noexcept
    { return m_type; }
    void setType(const QString &val) noexcept
    { m_type = val; }

    inline const QVariant & value() const noexcept
    { return m_value; }
    void setValue(const QVariant &val) noexcept
    { m_value = std::move(val); }

    bool operator<(const CnsVariantKey &o) const Q_DECL_NOTHROW
    {
        if(m_type=="enum")
        {
            CnsEnumPtr v1 = m_value.value<CnsEnumPtr>();
            CnsEnumPtr v2 = o.value().value<CnsEnumPtr>();
            return v1 < v2;
        }
        return m_value < o.value();
    }

private:
    QString m_type;
    QVariant m_value;
};

Q_DECLARE_METATYPE(CnsVariantKey)
typedef QMap<CnsVariantKey, QVariant> CNSVARIANTKEYMAP;

#endif // CNSVARIANTKEY_H
